-
Notifications
You must be signed in to change notification settings - Fork 10.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FIX] Incorrect display of "Reply in Direct Message" in MessageAction #17968
Conversation
Check that we either already have a DM room started with the message user or that we have the `create-d` permission to start one, otherwise hiding the reply in DM menu option. Currently if a user does not have the `create-d` permission and does not already have a DM started with a user, the "Reply in Direct Message" context menu is still displayed for messages even though clicking it will show the user a "User not found - Invalid room" page and "Not allowed [error-not-allowed]" toast message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello! So far this PR is looking good, I've mentioned some improvements that can be done in it. Thanks!
|
||
// Check if we already have a DM started with the message user (not ourselves) or we can start one | ||
const dmRoom = Rooms.findOne({ _id: [u._id, msg.u._id].sort().join('') }); | ||
const canAccessDM = dmRoom && Subscriptions.findOne({ rid: dmRoom._id, 'u._id': u._id }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe before doing multiple findOne
s, we can check if the user lack the permission, so we can avoid calling these methods when we don't need it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you suggesting something like this?
// Don't show reply option if we're messaging someone else and we don't have
// permission to start a new DM with them
if (u._id !== msg.u._id && !hasPermission('create-d')) {
const dmRoom = Rooms.findOne({ _id: [u._id, msg.u._id].sort().join('') });
if (!dmRoom || !Subscriptions.findOne({ rid: dmRoom._id, 'u._id': u._id })) {
return false;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MartinSchoeler are you suggesting something like ☝️ ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MartinSchoeler thoughts RE my suggested fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @MartinSchoeler still awaiting your feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, those changes are good! Sorry for the delay, I had some issues with my GH notifications
What's needed to get this moving along @MartinSchoeler ? |
Proposed changes
Check that we either already have a DM room started with the message user or that we have the
create-d
permission to start one, otherwise hiding the reply in DM menu option.Issue(s)
Currently if a user does not have the
create-d
permission and does not already have a DM started with a user, the "Reply in Direct Message" context menu option is still displayed for messages even though clicking it will show the user a "User not found - Invalid room" page and "Not allowed [error-not-allowed]" toast message.Screenshots
Types of changes
Checklist
Changelog
[FIX] Incorrect display of "Reply in Direct Message" in MessageAction
Further comments
Note I've left the tests in a separate commit for now as they weren't super simple due to some of the setup required to test this. I tried to find other examples of tests that did similar things but didn't really find anything suitable. Would be good to get some feedback as to if there would be a better way to do the setup?